package model

import (
	"time"
	"errors"
)

type MobileLogin struct {
	Uid         int64     `xorm:"pk"`
	Os   string    
	Version   string    
	LastLoginTime time.Time       
	CreateTime time.Time `xorm:"created"`
}

type MapMobileLogin map[int64]*MobileLogin

func GetMobileLoginFromUserIdContainer(userIdContainer IAdminUserIdContainer) (MapMobileLogin, error) {
	userIds := userIdContainer.GetUserIds()
	mobileLogins := make(MapMobileLogin)

	if len(userIds) <= 0 {
		return mobileLogins, nil
	}

	err := Orm.In("uid", userIds).Find(&mobileLogins)
	if err != nil {
		return nil, err
	}

	return mobileLogins, nil
}


func GetMobileLoginByUid(uid int64) (*MobileLogin, error){
	if uid <= 0 {
		return nil, errors.New("id empty")

	}

	mobileLogin := new(MobileLogin)
	ok, err := Orm.Id(uid).Get(mobileLogin)
	if err != nil {
		return nil, err
	}

	if ok {
		return mobileLogin, nil
	} else {
		return nil, ErrNotExist
	}
}


